var uid=$("#j_head").attr("uid"),uname=$("#j_head").attr("alt"),flevel=$("#j_head").attr("flevel");
function show_reply(a){$("#reply_div_"+a).show();$('#reply'+a).focus();}
function show_reply_hide(a){$("#reply_div_"+a).hide();}
function del_gbook(a,link_name,uid,id){confirmpop("删除 "+a+" 的留言吗？","删 除","window.location = '/index.php?module=board&mode=del&uid="+uid+"&link_name="+link_name+"&from=index&gid="+id+"'");}
function followTimeout(){if($("#act span.j").html()){a='<span class="s_both">互相关注 (好友)';}else{a='<span class="s_yi">已关注';}$("a.s_add,span.j").remove();$("a.s_mes").before(a+' &nbsp;<a class="blue" onclick="followList('+uid+',\''+uname+'\');" href="javascript:;">设置分组</a></span><span class="left f666">|</span>');$("div.bnav_line").after('<a onclick="act(\'unfollow\');" href="javascript:;">取消关注</a>');followList(uid,uname);$("b.loading").remove();}
function act(t){if(t=='comfirm_block'){confirmpop("确定要把"+uname+"加入黑名单吗？加入黑名单后"+uname+"将不能给你发短信息、留言、回复，也不能关注你","确 定","act('block');")}else{$.post('/ajax/buddys.ajax.php',{u:uid,t:t},function(d){if(d==2){show_login()}else{ga("my-spaceindex-"+t);if(t=='follow'){$("#act a.pmore").after('<b class="loading">&nbsp;</b>');setTimeout('followTimeout()',1000)}else if(t=='block'){location.reload()}else{$("#act a.pmore").after('<b class="loading">&nbsp;</b>');setTimeout('location.reload()',1000)}}})}}
function board_set_swf(id){$('#flash_'+id).show();$('#img_'+id).hide();$('#swf_play_'+id).html('<a class="blue" href="javascript:;" style="vertical-align:bottom;margin-left:3px;" onclick="board_close_swf('+id+',1)">收起播放器</a><br />');}
function board_close_swf(id){$('#flash_'+id).hide();$('#img_'+id).show();$('#swf_play_'+id).html('');}
function set_swf(swfid,html){if(!$('#swf_play_'+swfid).html()){var html_obj=new String(html);html_obj.replace('&lt;','<').replace('&gt;','>').replace('&quot;','"');$('#play_img_'+swfid).hide();$('#swf_play_'+swfid).html(html_obj+'<a class="blue" style="vertical-align:bottom;margin-left:3px;" onClick="set_swf('+swfid+',1)" href="javascript:;">收起播放器</a>')}else{$('#play_img_'+swfid).show();$('#swf_play_'+swfid).empty()}}
function send_msg(uid,username){
	$("body").prepend('<div id="send_msg_div" class="pop" style="display:none;"><div class="pop_content"><div class="pop_border"><h2 class="mpop"><a onclick="closepop()"><span>关闭</span></a><font id="send_title">给 '+username+' 发短消息</font></h2><form id="sendform" name="sendform" method="post" action=""><ul class="album_create"><li><em>短消息内容：</em><span><textarea name="fmsgs" id="fmsgs" class="j_enter" cols=25 rows=5></textarea></span></li><li style="padding-left:88px"><em></em><input name="msguid" value="'+uid+'" type="hidden"><input name="msgusername" value="'+username+'" type="hidden"><input name="" class="btns2 j_fmsgs" type="button" value="发 送" onclick="post_send()" />&nbsp;&nbsp;&nbsp;&nbsp;<input name="" type="button" class="btnb2" value="取 消" onclick="closepop();$(\'#send_msg_div\').remove();" /></li></ul></form></div></div></div>');
	var objWH=popTL("#send_msg_div"),tbT=objWH.split("|")[0]+"px",tbL=objWH.split("|")[1]+"px";
	$("#send_msg_div").css({top:tbT,left:tbL,display:""});$("#fmsgs").focus();popbg();
	$('textarea.j_enter').keydown(function(e){if(e.ctrlKey && e.keyCode == 13){var a=$(this).attr('id');$('input.j_'+a).click();}});
}
function post_send(){
	var $tip = $('#sendform');

	var uid = $tip.find('input[name="msguid"]').val(),
		user = $tip.find('input[name="msgusername"]').val(),
		text = $.trim($tip.find('textarea[name="fmsgs"]').val()),
		if_sebox = 0;

	if(text == ''){$("#fmsgs").focus();return false;}else if(uid == '' || user == ''){alert("出错了，请刷新后重试下");return false;}
	closepop();
	$.post("/message_act.php",{act:"send",touid:uid,touser:user,if_sebox:if_sebox,content:text,token:$("#token").val()},function (data){
		if(data == 1){
			show_message("发送成功");$("#send_msg_div").remove();
		}else if(data == 2){
			show_message("<div class=tips_pop>出错了，请刷新后重试下</div>");
		}else if(data == 3){
			show_message("<div class=tips_pop>信息过长！</div>");
		}else{
			show_message(data);
		}
	});
}

function followList(userid,username){
	$("#act a.pmore").after('<b class="loading">&nbsp;</b>');
	$.post('/ajax/buddys.ajax.php',{u:uid,t:'getList'},function(d){
		if(d && d!=2)
		{
			$("body").before('<div id="friend_attr" class="pop" style="width:400px;display:none;"><div class="pop_content"><form id="edit_f_form" name="edit_f_form"><h2 class="mpop"><a onclick="closeFollowList();" title="关闭"></a><span id="now_load">设置分组和备注</span></h2><div class="friend_group"><h4>把 <strong class="f666" id="friend_name">'+uname+'</strong> 加入分组：(<a class="blue" target="_blank" href="/help.php#social-4">分组有什么用？</a>)</h4><ul class="firend_att" id="friend_edit_ul"><li><label for="g_0"><input name="group_arr[]" type="checkbox" value="0" id="g_0" /> 首页分组</label></li>'+d+'</ul><ul class="friend_brief"><li class="friend_add"><input name="new_name_check" type="checkbox" value="1" /><input id="new_name" name="new_name" type="text" maxlength="20" value="新建分组" style="width:85px" onclick="hide_group()"/></li><li class="friend_mark">备注：<span class="f666">(最多10个汉字)</span><input name="info" type="text" maxlength="20" /></li><li class="act"><input name="user_id" type="hidden" value="'+uid+'" /><input type="submit" value="保 存" class="btns2" /> &nbsp; &nbsp;<input type="button" onclick="closeFollowList();" value="取 消" class="btnb2" /></li></ul></div></form></div></div>');
			popbg();var objWH=popTL("#friend_attr"),tbT=objWH.split("|")[0]+"px",tbL=objWH.split("|")[1]+"px";$("#friend_attr").css({top:tbT,left:tbL,display:""});$("b.loading").remove();
			$("#edit_f_form").submit(function(){sub_friend();return false;});

	$.post('/ajax/friend.ajax.php',{type:2,uid:userid},function(data){
		if(data != 2){
			var my_arr = eval("("+data+")"),f_e_ul_obj = document.getElementById('friend_edit_ul'),input_obj = f_e_ul_obj.getElementsByTagName('input'),i_o_l = input_obj.length;
			for(q=0;q<i_o_l;q++){
				input_obj[q].checked = false;
			}
			for(q=0;q<i_o_l;q++){
				var ival = input_obj[q].getAttribute('value');
				for(n=0;n<my_arr.length;n++){
					if(ival == my_arr[n]){
						input_obj[q].checked = true;
					}
				}
			}
		}
	});
	$.post('/ajax/friend.user.ajax.php',{type:1,uid:userid},function(data){
		if(data != ''){
			document.edit_f_form.info.value = data;
		}else{
			document.edit_f_form.info.value = '';
		}
	});
		}else{
			$("b.loading").remove();return false;
		}
	});

}

function hide_group(){
	if(document.edit_f_form.new_name.value == "新建分组"){
		document.edit_f_form.new_name.value = "";
		document.edit_f_form.new_name_check.checked = true;
	}
	if(document.edit_f_form.new_name.value != ""){
		document.edit_f_form.new_name_check.checked = true;
	}
	$("#new_name").css("color","#111");
}
function sub_friend(){
	hide_group();
	var f_e_ul_obj = document.getElementById('friend_edit_ul');
	var input_obj = f_e_ul_obj.getElementsByTagName('input');
	var i_o_l = input_obj.length;
	var check_val = 0;
	var group_str = '';
	var new_name_val = document.edit_f_form.new_name.value;
	var info_val = document.edit_f_form.info.value;
	var uid = document.edit_f_form.user_id.value;
	for(q=0;q<i_o_l;q++){
		if(input_obj[q].checked == true){
			check_val = 1;
			group_str += input_obj[q].value+"&";
		}
	}
	if(check_val == 0 && (document.edit_f_form.new_name_check.checked == false || document.edit_f_form.new_name.value == "") && document.edit_f_form.info.value == ''){
		alert('至少要输入一项内容');return false;
	}
	$.post('/ajax/friend.user.ajax.php',{type:2,groupstr:group_str,new_name_str:new_name_val,info_val_txt:info_val,user_id:uid},function(data){
		if(data != 'error'){
			if(new_name_val != ""){
				var li_objs = document.createElement('li');
				f_e_ul_obj.appendChild(li_objs);
				li_objs.innerHTML = '<label for="g_'+data+'"><input name="group_arr[]" type="checkbox" value="'+data+'" id="g_'+data+'" /> '+new_name_val+'</label>';
			}
		}
		document.edit_f_form.new_name.value = '';
		document.edit_f_form.new_name_check.checked = false;
		closeFollowList();
	});
}

function closeFollowList(){$("#friend_attr").remove();closepop();}

$(function(){
	$('input.j_board_reply').click(function(){var id = $(this).attr('mid'),reply_content =  $("#reply"+id).val();if(reply_content!=''){$("#reply_button_"+id).attr("disabled",true).after('<b class="loading">&nbsp;</b>');$("#form"+id).submit();$("#reply_button2_"+id).hide();}else{$('#reply'+id).focus();return false;}});
	$('#sub_fst_form2').submit(function(){if($('#board_input').val().length > 200){ alert('你输入的内容太长，请控制在200个文字以内！！！');$('#board_input').focus();return false;}if($('#board_input').val()==''){$('#board_input').focus();return false;}else{$('#replaybutton').attr("disabled",true).after('<b class="loading">&nbsp;</b>');}});
	$('a.j_board_p').click(function(){var mid=$(this).attr('mid');$('#j_'+mid).hide();$('#add_li_'+mid).show();$('#goonadd_'+mid).show();});
	var j = 1;
	$('a.j_board_p2').click(function(){
			var mid=$(this).attr('mid');
			if(j < 3){
			var new_li_uppic = document.createElement('li');
			document.getElementById('add_li_'+mid).appendChild(new_li_uppic);
			new_li_uppic.innerHTML = '<input name="uppic[]" type="file" class="inputfile" id="uppic[]" />';
			j++;
			if(j == 3){document.getElementById('goonadd_'+mid).style.display = 'none';}
			}
			});
	$('#j_board_p').click(function(){$('#j_board_p').hide();$('#add_li').show();$('#goonadd').show();});
	var i = 1;
	$('#j_board_p2').click(function(){
			if(i < 3){
			var new_li_uppic = document.createElement('li');
			document.getElementById('add_li').appendChild(new_li_uppic);
			new_li_uppic.innerHTML = '<input name="uppic[]" type="file" class="inputfile" id="uppic[]" />';
			i++;
			if(i == 3){$('#goonadd').hide();}
			}
			});
	$("#j_s_hobby").click(function(){$("#j_hobby_m").show();$("#j_s_hobby").hide();});
	$("div.ga a").click(function(){ga("my-space-"+$(this).parents("div.ga").attr("id")+"-"+$(this).text());});
	$("#act a.pmore").click(function(){if($("#act ul").css("display")=='none'){$(this).addClass("bnav_over");$("#act ul").show();}else{$("#act a.pmore").removeClass("bnav_over");$("#act ul").hide();}});
	$(document).click(function(){$("#act a.pmore").removeClass("bnav_over");$("#act ul").hide();});
	$("#act ul,#act a.pmore").click(function(e){e.stopPropagation();});
});
